<?php
include("../contents.php");
include("../security.php");
include("../settings.php");
include("../database.php");
include("../navigation.php");
if(!empty($_GET["dir"]) || (isset($_GET["dir"]) && $_GET["dir"]==0)) {
	if ($_GET["dir"]==0 && (isset($_GET["pres"]) && Contents::presence_rights($_GET["pres"]))) {
		$row_act->id=0;
		$row_act->presence=$_GET["pres"];
		$row_act->name="/";
	} else {
		$act_dir=mysql_query("SELECT * FROM ". $GLOBALS["db_pref"] ."navigation WHERE id='". $_GET["dir"] ."'");
		if (mysql_num_rows($act_dir)==1) {
			$row_act=mysql_fetch_object($act_dir);
			if (!Contents::presence_rights($row_act->presence)) {
				die("Sie haben keinen Zugriff auf dieses Verzeichnis");
			}
		} else {
			die("Da ist irgendwas schief gelaufen.");
		}
	}
	$GLOBALS["linkzusatz"]="&amp;dir=". $row_act->id ."&amp;pres=". $row_act->presence;
	if(!empty($_POST["language"]) && isset($_POST["langname"])) {
		mysql_query("DELETE FROM ". $GLOBALS["db_pref"] ."navigation_language WHERE navid='". $row_act->id ."' and language='". $_POST["language"] ."'");
		mysql_query("INSERT INTO ". $GLOBALS["db_pref"] ."navigation_language SET navid='". $row_act->id ."', language='". $_POST["language"]."', name='". utf8_decode($_POST["langname"]) ."'");
	}
}
echo "<"."?xml version=\"1.0\"?".">";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>Administration</title>
    <link media="screen" rel="stylesheet" href="css/style.css" type="text/css" />
    <script src="js/scripts.js" type="text/javascript"></script>
  </head>

  <body id="edit">
    <form id="linkform" action="<?php echo $_SERVER["PHP_SELF"]; ?>?<?php echo $GLOBALS["linkzusatz"]; ?>" method="post">
    <p id="pageheadline">Sprache:</p>
    	<select name="language" size="1">
    		<option value="">--- Bitte w&auml;hlen ---</option>
    		<?php
    		$langs=mysql_query("SELECT * FROM ". $GLOBALS["db_pref"] ."languages where shortname!='". getsetting("standard_language") ."' order by name");
    		for($i=0; $i<mysql_num_rows($langs); $i++) {
    			$row_lang=mysql_fetch_object($langs);
    			?><option value="<?php echo $row_lang->shortname; ?>"><?php echo $row_lang->name; ?></option><?php
    		}
    		?>
    	</select>
    <input type="text" value="" name="langname" size="40" maxlength="255" />
    <p id="pageheadline"><input type="submit" value="Speichern" /> <input type="button" value="Schliessen" onclick="window.location.href='/admin_navigation_overview.php?dir=<?php echo $row_act->subof ?>&pres=<?php echo $row_act->presence; ?>'" /></p>
   	</form>
   	<br />
   	<p id="pageheadline">Sprachen:</p>
   	<table style="border:0px; padding: 5px; margin:0px;">
  		<?php
  		$langs=mysql_query("SELECT * FROM ". $GLOBALS["db_pref"] ."languages where shortname!='". getsetting("standard_language") ."' order by name");
  		for($i=0; $i<mysql_num_rows($langs); $i++) {
  			$row_lang=mysql_fetch_object($langs);
  			?>
			<tr>
   	    		<td><?php echo $row_lang->name; ?></td>
   	    		<td><?php
   	    		$translation=mysql_query("SELECT * FROM ". $GLOBALS["db_pref"] ."navigation_language WHERE navid='". $row_act->id ."' and language='". $row_lang->shortname ."'");
   	    		if(mysql_num_rows($translation)>0) {
   	    			$row_translation=mysql_fetch_object($translation);
   	    			if($row_translation->name!="") {
   	    				echo $row_translation->name;
   	    			} else {
   	    				echo "<em>Dieser Punkt wird nicht angezeigt</em>";
   	    			}
   	    		} else {
   	    			echo "<em>Noch keine &Uuml;bersetzung vorhanden.</em>";
   	    		}
   	    		?></td>
   	  		</tr>
  			<?php
  		}
  		?>
   	</table>
  </body>
</html>